package com.sky.controller.admin;

/**
 * @Author: WangHongKun
 * @Date: 2022/9/22 16:58
 * @Email: 2028911483@qq.com
 * @Phone: 18683977706
 */

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.dto.DishDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import com.sky.service.DishService;
import com.sun.org.apache.bcel.internal.generic.RETURN;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  分类
 */
@RestController("AdminCategoryController")
@RequestMapping("/admin/category")
@Slf4j
@Api(tags = "分类相关的接口")
public class CategoryController {

    @Autowired
    private CategoryService  categoryService;



    /**
     * 修改分类
     * @param categoryDTO
     * @return
     */
    @ApiOperation("修改分类接口")
    @PutMapping
    public Result modify(@RequestBody  CategoryDTO categoryDTO){
        log.info("修改的分类信息：{}",categoryDTO);
        categoryService.modify(categoryDTO);
        return Result.success();
    }


    /***
     *
     * @param categoryPageQueryDTO
     * @return
     */
    @ApiOperation("分页查询接口")
    @GetMapping("/page")
    public Result<PageResult> PageQuery(CategoryPageQueryDTO categoryPageQueryDTO){
        log.info("分页查询的信息：{}",categoryPageQueryDTO);
        PageResult pageResult = categoryService.PageQuery(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 启动禁用
     * @param status
     * @param id
     */
    @ApiOperation("启动禁用接口")
    @PostMapping("/status/{status}")
    public  Result startOrStop( @PathVariable Integer status , long id ){
        log.info("启动禁用信息：{}",status,id);
        categoryService.startOrStop(status,id);
        return  Result.success();
    }

    /**
     * 新增分类
     * @param categoryDTO
     * @return
     */
    @ApiOperation("新增分类接口")
    @PostMapping
    public Result  add(@RequestBody CategoryDTO categoryDTO){
        log.info("新增的分类信息：{}",categoryDTO);
        categoryService.add(categoryDTO);
        return Result.success();
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @ApiOperation("根据id删除分类接口")
    @DeleteMapping
    public  Result  Delete(long id){
        log.info("删除的分类id：{}",id);
        categoryService.Delete(id);
        return Result.success();
    }


    /**
     *根据类型查询分类
     * @param type
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据类型查询分类接口")
    public Result<List<Category>>   QueryByType(Integer type){
        log.info("查询的类型：{}",type);
        List<Category> categoryList = categoryService.QueryBYType(type);
        return Result.success(categoryList);
    }




}
